package domain

type CodeFileInfo struct {
	Package    *PackageInfo `json:"-"`
	LocalFile  string
	RawLines   []string
	CleanLines []string
	Imports    []*ImportInfo
	Structs    []*StructInfo

	AdditionalImports []*ImportInfo
	AdditionalLines   []string
}

func NewCodeFileInfo() *CodeFileInfo {
	it := new(CodeFileInfo)
	it.RawLines = []string{}
	it.Imports = []*ImportInfo{}
	it.Structs = []*StructInfo{}
	it.AdditionalImports = []*ImportInfo{}
	it.AdditionalLines = []string{}
	return it
}

func (me *CodeFileInfo) AppendImport(it *ImportInfo) {
	me.Imports = append(me.Imports, it)
}

func (me *CodeFileInfo) AppendStruct(it *StructInfo) {
	me.Structs = append(me.Structs, it)
}

func (me *CodeFileInfo) Clone() interface{} {
	it := new(CodeFileInfo)
	it.Package = me.Package
	it.LocalFile = me.LocalFile

	it.RawLines = make([]string, len(me.RawLines))
	for i, v := range me.RawLines {
		it.RawLines[i] = v
	}

	it.CleanLines = make([]string, len(me.CleanLines))
	for i, v := range me.RawLines {
		it.CleanLines[i] = v
	}

	it.Imports = make([]*ImportInfo, len(me.Imports))
	for i, v := range me.Imports {
		it.Imports[i] = v.Clone().(*ImportInfo)
		it.Imports[i].CodeFile = it
	}

	it.Structs = make([]*StructInfo, len(me.Structs))
	for i, v := range me.Structs {
		it.Structs[i] = v.Clone().(*StructInfo)
		it.Structs[i].CodeFile = it
	}

	it.AdditionalImports = make([]*ImportInfo, len(me.AdditionalImports))
	for i, v := range me.Imports {
		it.AdditionalImports[i] = v.Clone().(*ImportInfo)
		it.AdditionalImports[i].CodeFile = it
	}

	it.AdditionalLines = make([]string, len(me.AdditionalLines))
	for i, v := range me.RawLines {
		it.AdditionalLines[i] = v
	}

	return it
}
